package com.szzg10.thinking.chapter11;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class InterfaceVsInterator {

	public static void main(String[] args) {
		List<Pet> listPet = Arrays.asList(new Rat(), new Manx(), new Cymric(), new Mutt(), new Pug(), new Cymric(), new Pug(),new Manx());
		Set<Pet> setPet = new HashSet<Pet>(listPet);
		
		Map<String, Pet> mapPet = new HashMap<String, Pet>();
		String[] names = ("Ralph, Eric, Robin, Lacey, Britney, Sam, Spot, Fluffy").split(", ");
		for(int i = 0; i < names.length; i++) {
			mapPet.put(names[i], listPet.get(i));
		}
		
		display(listPet);
		display(setPet);
		display(listPet.iterator());
		display(setPet.iterator());
		
		System.out.println(mapPet);
		System.out.println(mapPet.keySet());
		
		display(mapPet.values());
		display(mapPet.values().iterator());
	}
	
	public static void display(Iterator<Pet> iterator) {
		while(iterator.hasNext()) {
			System.out.print(iterator.next() + ", ");
		}
		System.out.println();
	}
	
	public static void display(Collection<Pet> collection) {
		for(Pet element: collection) {
			System.out.print(element + ", ");
		}
		System.out.println();
	}
}
